var mongoose = require("mongoose");
mongoose.connect('mongodb://localhost/test'); 

var db = mongoose.connection;
db.once('open', function(err){
    console.log("数据库成功打开！");
});

var blogSchema = new mongoose.Schema({
    title: String,
    author: String,
    body: String,
    comments: [{body: String,date: Date}],
});

blogSchema.methods.Comment = function(obj,callback){        // 发表评论
    this.comments.push(obj);        // 把评论push进去
    this.save();
}

var Blog = mongoose.model('Blog',blogSchema);
// var blog = new Blog({
//     "title": "哈哈哈",
//     "author": "陈伟霆",
//     "body" : "啦啦啦啦"
// });

Blog.findOne({"title":"哈哈哈"},function(err,blog){    // 发表评论
    if(!blog){
        return;
    }
    blog.Comment({"body":"评论内容","date": new Date()});
})